package com.disease.api.service.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Value("${spring.datasource.dynamic.datasource.base.url}")
    String url;

    @Value("${spring.datasource.dynamic.datasource.base.username}")
    String username;

    @Value("${spring.datasource.dynamic.datasource.base.password}")
    String password;

    @Value("${spring.datasource.dynamic.datasource.base.driver-class-name}")
    String driverClassName;

    @Bean(name = "resourceJdbcTemplate")
    public JdbcTemplate inditeJdbcTemplate() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return new JdbcTemplate(dataSource);
    }
}
